import request from "@/utils/request";
import { useUserStore } from '@/stores/user';
const getToken = () => {
    const userStore = useUserStore();
    return userStore.token;
};

//获取地址列表接口
export const getAddressList = () => {
  return request.get('/address',{
    headers: {
      'Authorization': getToken() // 获取用户 token
    }
  });
}

//增加地址接口
export const addAddress = (recipientName,phone,address) =>{
  return request.post('/address',{
    recipientName,
    phone,
    address
  }, {
    headers: {
      'Authorization': getToken() // 获取用户 token
    }
  });
}

// 修改地址接口
export const editAddress = (addressId, recipientName, phone, address) => {
  return request.put(`/address/${addressId}`, {
    recipientName,
    phone,
    address
  }, {
    headers: {
      'Authorization': getToken() // 获取用户 token
    }
  })
}

// 删除地址接口
export const deleteAddress = (addressId) => {
  return request.delete(`/address/${addressId}`, {
    headers: {
      'Authorization': getToken() // 获取用户 token
    }
  })
}
